package main

import "math"

func main() {
	s := 7
	nums := []int{2, 3, 1, 2, 4, 3}
	minSubArrayLen(s, nums)
}

func minSubArrayLen(s int, nums []int) int {
	num1 := []int{}
	temp := 0
	for i := 0; i < len(nums); i++ {
		if temp < s {
			temp += nums[i]
			num1 = append(num1, temp-s)
		} else {
			temp = nums[i]
			num1 = append(num1, temp-s)
		}
	}
	length := 0
	min_ := len(nums)
	for _, i := range num1 {
		if i < 0 {
			length += 1
		} else {
			if length < min_ {
				min_ = length
			}
			length = 0
		}
	}
	return min_ + 1
}



func minSubArrayLen1(s int, nums []int) int {
	n := len(nums)
	if n == 0 {
		return 0
	}
	ans := math.MaxInt32
	start, end := 0, 0
	sum := 0
	for end < n {
		sum += nums[end]
		for sum >= s {
			ans = min(ans, end - start + 1)
			sum -= nums[start]
			start++
		}
		end++
	}
	if ans == math.MaxInt32 {
		return 0
	}
	return ans
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}